define curenv
    print *(cpus[cpunum()].cpu_env)
end

define pgdir

    set $pgdir = $arg0

    if ($arg1)
        print "arg1"
    end

    set $pd_idx = $addr>>22

    set $pt_idx = ($addr>>12)&0x3ff

    set $page_off = ($addr&0xfff)
    set $i = 0

    while ($i < 1024) 
        show_pte *($pgdir)
        set $i = $i + 1
    end
end

define showFile
    set $base = (char*)$arg0

    set $fileSize = *(uint32_t*)($base+128)

    set $type = *(uint32_t*)($base+132)

    if ($type == 1)
        printf "name='%s',fileSize=%d,type='dir'\n",$base,$fileSize
    else
        if ($type == 0)
            printf "name='%s',fileSize=%d,type='regular'\n",$base,$fileSize
        else
            printf "name='%s',fileSize=%d,type='unknown'\n",$base,$fileSize
        end
    end
end

define show_pte
    set $pte = $arg0

    set $pFlag = $pte & 1 ? 'P' : ' '
    set $wFlag = $pte & 2 ? 'W' : 'R'
    set $uFlag = $pte & 4 ? 'U' : 'S'

    printf "phy: %x, %c%c%c\n", $pte&(~0xfff), $pFlag, $wFlag, $uFlag

end


